import Vue from 'vue'
import cookie from './cookie'
// import store from '../vuex/store'

const Login = {
  baseGetOpenid: async (param) => {
    const res = await Vue.http['get'](`/lottery/api/v1/getUserOpenid?code=${param.code}`)
    console.log('baseGetOpenid:', res.body)
    if (res.body.status) {
      cookie.set('openid', res.body.data.openid)
      cookie.set('userId', res.body.data.userId)

      // 存储openid
      // store.commit('updateUser', {
      //   openid: res.body.data.openid,
      //   userId: res.body.data.userId
      // })
    } else {
      throw new Error(res.body.msg)
    }
  },
  snsapiGetOpenid: async (param) => {
    const res = await Vue.http['get'](`/lottery/api/v1/snsapiUserOpenid?code=${param.code}`)
    console.log('snsapiGetOpenid:', res.body)
    // alert(res.body.data)
    if (res.body.status) {
      cookie.set('openid', res.body.data.openid)
      cookie.set('userId', res.body.data.userId)
      location.href = cookie.get('beforeLoginUrl')
    } else {
      throw new Error(res.body.msg)
    }
  }
}
export default Login
